package com.poetize.plus.controller.ui;

import com.poetize.plus.entity.vo.*;
import com.poetize.plus.service.*;
import com.poetize.plus.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.security.PermitAll;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author zuosy
 * @created 2024/4/1 11:17
 */
@Tag(name = "主页信息")
@RestController
@RequestMapping("/home")
@RequiredArgsConstructor
public class HomeController {

    private final MenuService menuService;

    private final ArticleService articleService;

    private final NoticeService noticeService;

    private final WebInfoService webInfoService;

    private final SortService sortService;

    private final LabelService labelService;

    private final BackgroundImageService backgroundImageService;

    @PermitAll
    @GetMapping("/getMenu")
    @Operation(summary = "获取菜单")
    public R<List<MenuTreeVO>> getMenu(){
        return R.ok(menuService.getHomeMenu());
    }

    @PermitAll
    @GetMapping("/getWebInfo")
    @Operation(summary = "获取网站信息")
    public R<HomeWebInfoVO> getWebInfo(){
        return R.ok(webInfoService.getWebInfo());
    }

    @PermitAll
    @GetMapping("/getStatistics")
    @Operation(summary = "获取卡片统计信息")
    public R<StatisticsVO> getStatistics(){
        return R.ok(webInfoService.getStatistics());
    }

    @PermitAll
    @GetMapping("/getRecommendArticle")
    @Operation(summary = "获取推荐文章列表")
    public R<List<HomeRecommendArticleVO>> getRecommendArticle(){
        return R.ok(articleService.getHomeRecommendArticle());
    }

    @PermitAll
    @GetMapping("/getArticle")
    @Operation(summary = "获取文章列表")
    public R<Map<Long, List<HomeArticleVO>>> getArticle(){
        return R.ok(articleService.getHomeArticle());
    }

    @PermitAll
    @GetMapping("/getNotice")
    @Operation(summary = "获取公告信息")
    public R<List<NoticeVO>> getNotice(){
        return R.ok(noticeService.getHomeNotice());
    }

    @PermitAll
    @GetMapping("/getSort")
    @Operation(summary = "获取分类")
    public R<List<SortVO>> getSort(){
        return R.ok(sortService.getHomeSort());
    }

    @PermitAll
    @GetMapping("/getLabel")
    @Operation(summary = "获取标签")
    public R<List<LabelVO>> getLabel(){
        return R.ok(labelService.getHomeLabel());
    }

    @PermitAll
    @GetMapping("/getRandomBackgroundImage")
    @Operation(summary = "获取随即背景图")
    public R<String> getRandomBackgroundImage(){
        return R.ok(backgroundImageService.getRandomBackgroundImage());
    }
}
